//-----------------------------------------------------------------------
// <copyright file="SupplierService.cs" company="Pyramid Consulting">
//     Copyright (c) Pyramid Consulting. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------	

using System;
using System.Collections;
using MyFramework;
using MIMS.WRS.Entities;
using MIMS.WRS.Data;
    
namespace MIMS.WRS.Business
{   
	/// <summary>
	/// 
	/// </summary> 
    public class SupplierService
    {
        #region Supplier

        public static void CreateSupplier(Supplier supplier)
        {            
            try
            {
                SupplierDAO supplierDAO = new SupplierDAO();
                supplierDAO.CreateSupplier(supplier);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessCreateSupplierException, ex);
            }
        }        

        public static void UpdateSupplier(Supplier supplier)
        {            
            try
            {
                SupplierDAO supplierDAO = new SupplierDAO();
                supplierDAO.UpdateSupplier(supplier);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessUpdateSupplierException, ex);
            }
        }        

        public static void DeleteSupplier(string supplierCode)
        {            
            try
            {
                SupplierDAO supplierDAO = new SupplierDAO();
                supplierDAO.DeleteSupplier(supplierCode);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessDeleteSupplierException, ex);
            }
        }
        
        public static Supplier GetSupplier(string supplierCode)
        {            
            try
            {
                SupplierDAO supplierDAO = new SupplierDAO();
                return supplierDAO.GetSupplier(supplierCode);                
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessGetSupplierException, ex);
            }
        }                

        public static SupplierCollection GetSuppliers(SupplierColumns orderBy, OrderDirection orderDirection)
        {            
            try
            {
                SupplierDAO supplierDAO = new SupplierDAO();
                return supplierDAO.GetSuppliers(orderBy, orderDirection);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessGetSuppliersException, ex);
            }
        }        

        public static SupplierCollection GetSuppliers(SupplierColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                SupplierDAO supplierDAO = new SupplierDAO();
                return supplierDAO.GetSuppliers(orderBy, orderDirection, page, pageSize, out totalRecords);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessGetSuppliersException, ex);
            }
        }        

        #endregion

		public static SupplierCollection GetSuppliers(int conPointID)
		{            
			try
			{
				SupplierDAO supplierDAO = new SupplierDAO();
				return supplierDAO.GetSuppliers(conPointID);
			}
			catch (BusinessException)
			{
				throw;
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new BusinessException(SR.BusinessGetSuppliersException, ex);
			}
		}    
  
		public static SupplierCollection GetAllSuppliers()
		{            
			try
			{
				SupplierDAO supplierDAO = new SupplierDAO();
				return supplierDAO.GetAllSuppliers();
			}
			catch (BusinessException)
			{
				throw;
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new BusinessException(SR.BusinessGetSuppliersException, ex);
			}
		}     
    }
}